package top.kaoshanji.p1ch04a;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.text.NumberFormat;
import java.text.ParseException;

/**
 * 代码清单 p1ch04a-12：格式化和解析数字的示例
 * author kaoshanji
 * ^_^
 * create time 2025/1/15 19:43
 */
public class NumberFormatExample01 {

    private static final Logger logger = LogManager.getLogger(NumberFormatExample01.class);

    public static void main(String[] args) throws ParseException {
        logger.info("...代码清单 p1ch04a-12：格式化和解析数字的示例...");

        NumberFormat format = NumberFormat.getNumberInstance();

        double num = 100.5;
        format.setMinimumFractionDigits(3);
        format.setMinimumIntegerDigits(5);
        String numFormat = format.format(num);
        logger.info("...numFormat:{}...", numFormat);

        String numStr = "523.34";
        format.setParseIntegerOnly(true);
        Number numStrParse = format.parse(numStr);
        logger.info("...numStrParse:{}...", numStrParse);

    }

}
